﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;
using WinFormsApp1.TongShiWei.PigData;

namespace WinFormsApp1.TongShiWei.segmentationData
{
    
    public partial class DepotData_ : UIForm
    {
        public DepotData_()
        {
            InitializeComponent();
            //获取仓库表信息
            GetDepotData();
            
        }
        public event EventHandler<DepotData_>? ValueSubmitted;
        public class valueEventAge : EventArgs
        { 
            public string value {  get; }
            public valueEventAge(string value)
            {
                this.value = value;
            }
        }

        private void button1_click(object sender, EventArgs e)
        {
            SegmentationContext segmentationContext = new(null);
            //ValueSubmitted += segmentationContext.SegmentationContext_ValeSubmitted;
           
        }

        List<_DepotData> depotData_s = new List<_DepotData>();
        public async void GetDepotData()
        {
            List<_DepotData> depotData_ = new List<_DepotData>();
            //http://localhost:5106/api/Tsw/ShowDepotData
            var res = await HttpClientHelper.RequestUrl<_DepotData, ApiResult<List<_DepotData>>>(URLCommon.Url2, "/TSW/ShowDepotData", HttpClientHelper.MethodType.GET);
            if (res.Code > 0)
            {
                depotData_.AddRange(res.Data);
                int x = 10; int y = 70; int i = 1;
                foreach (var item in res.Data)
                {
                    Button button = new Button()
                    {
                        Location = new Point(x, y),
                        Size = new System.Drawing.Size(150, 80),
                        AutoSize = true,
                        Name = item.DepotTypeId.ToString(),
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = Color.White,
                    };
                    button.Text = item.DepotTypeName;
                    button.Click += new System.EventHandler(Button_Cliek);
                    this.Controls.Add(button);
                    if (i == 5)
                    {
                        x = 10;
                        y += 90;
                        i = 1;
                    }
                    else
                    {
                        x += 165;
                        i++;
                    }
                };
            }
        }
        /// <summary>
        /// 跳转页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public event Action<int> GetDepotIdData;
        public async void Button_Cliek(object sender, EventArgs e)
        {
            var data = sender as Button;
            var DepotName = data.Name;
            GetDepotIdData?.Invoke(Convert.ToInt32(DepotName));
            this.Hide();
        }
        public class _DepotData
        {
            /// <summary>
            /// 仓库类型ID
            /// </summary>
            public int DepotTypeId { get; set; }
            /// <summary>
            /// 仓库类型名称
            /// </summary>
            public string DepotTypeName { get; set; } = string.Empty;
            /// <summary>
            /// 是否删除仓库类型{false=不删除；true=删除}
            /// </summary>
            public bool IsDepotType { get; set; }
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            this.Hide();
        }
    }
}
